package com.oa.co.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oa.co.mapper.OrderRoomMapper;
import com.oa.co.pojo.OrderRoom;
import com.oa.co.service.OrderRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Lone Ranger
 */
@Service("OrderRoomService")
public class OrderRoomServiceImpl implements OrderRoomService {

    @Autowired
    private OrderRoomMapper orderRoomMapper;

    @Override
    public Integer addOrder(OrderRoom orderRoom) {
        return orderRoomMapper.addOrder(orderRoom);
    }

    @Override
    public PageInfo<OrderRoom> getAllOrders(Integer pageNum, Integer limit, String username, String department) {
        OrderRoom orderRoom = new OrderRoom();
        orderRoom.setUsername(username);
        orderRoom.setDepartment(department);

        // 传入页码 和 每页的记录数
        PageHelper.startPage(pageNum, limit);
        List<OrderRoom> students = orderRoomMapper.findOrderByCondition(orderRoom);
        // 将分页结果装载pageInfo对象中
        PageInfo<OrderRoom> pageInfo = new PageInfo<>(students);

        return pageInfo;
    }

    @Override
    public Integer modifyOrder(OrderRoom orderRoom) {
        return orderRoomMapper.modifyOrder(orderRoom);
    }

    @Override
    public Integer deleteOrder(String order_id) {
        return orderRoomMapper.deleteOrder(order_id);
    }

    @Override
    public Integer deleteOrderMulti(List<OrderRoom> list) {
        return  orderRoomMapper.deleteOrderMulti(list);
    }
}
